<%-- 
    Document   : cart
    Created on : Jan 14, 2013, 2:46:43 AM
    Author     : SONY
--%>

<%@page import="model.ItemCart"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.ShoppingCart"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    ShoppingCart shopping_cart = (ShoppingCart) session.getAttribute("shopping_cart");
    if(shopping_cart.getAllItemCart().isEmpty()) {
%>
<p style="font-weight:bold;">Không có bất kỳ sản phẩm nào trong giỏ hàng.</p>
<% } else { %>

<table id="cart" border=1 cellspacing=0 cellpadding=4 bordercolor=lightgray width="100%">
	<tr bgcolor=#dadddd>
		<th>#</th>
		<th>Hình Ảnh</th>
		<th>Mã Sản Phẩm</th>
		<th>Tên Sản Phẩm</th>
		<th align=center>Đơn Giá (đ)</th>
		<th>Số Lượng</th>
		<th>Thành Tiền (đ)</th>
                <th>-</th>
	</tr>
<% 
    ArrayList<ItemCart> lstItemCart = shopping_cart.getAllItemCart();
    int j = 0;
    for(int i = 0; i < lstItemCart.size(); i++) {
        String color = ++j % 2 == 0 ? "#f9e7dd" : "#eec7b7";
        String pid = lstItemCart.get(i).getProductID();
        String pname = lstItemCart.get(i).getProductName();
        String imagename = lstItemCart.get(i).getImageName();
        double unitpricefmt = lstItemCart.get(i).getUnitPrice();
        int qty = lstItemCart.get(i).getQuantity();
        double totallinefmt = lstItemCart.get(i).getTotalLine();
%>
<form method="post" name="frmItemCart" action="<c:url value="/nonmember/update_cart.do" />">
	<tr bgcolor="<%=color%>">
		<td align=center><%=j%></td>
		<td align=center><a href="./product_details.jsp?<%=pid%>"><img width=50 title="<%=pname%>" height=50 src="../images/products/<%=imagename%>" /></a></td>
		<td align=center><%=pid%></td>		
		<td align=center><%=pname%></td>
		<td align=right><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=unitpricefmt%>"/></td>
                <td align=center>
                    <input type="hidden" name="ProductID" value="<%=pid%>"/>
                    <input type=text name="quantity" autocomplete="off"  value="<%=qty%>" size="6" style="text-align: right">
                </td>
		<td align=right><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=totallinefmt%>"/></td>
                <td><input type="submit" class="button" value="Cập Nhật"/></td>
	</tr>
        </form>

<% } %>
<% double totalfmt = shopping_cart.TotalPrice(); %>
	<tr bgcolor=#dadddd>
            <td colspan=6 align="right" style="font-weight: bold">
                Tổng Tiền (đ) 
            </td>
		<td align="right" style="font-weight: bold">
			<fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=totalfmt%>"/>
		</td>
                <td align="center">-</td>
	</tr>
	<tr>
		<td colspan=8 style="font-style: italic;color: red;">
			Nhập số lượng 0 để xóa 1 sản phẩm từ giỏ hàng
		</td>
	</tr>
	<tr>
            <form method="post" name="frmCart">
		<td colspan=8 align=left>
                    <input type="submit" class="button" onclick="frmCart.action='<c:url value="/nonmember/delete_cart.do" />'" value="Xóa Tất Cả" />
			<input type="submit" class="button" onclick="frmCart.action='<c:url value="/nonmember/order_step1.jsp" />'" value="Thanh Toán"/>
		</td>
            </form>
	</tr>
</table>

<% 
if(((HttpServletRequest) request).getAttribute("errorMsg") != null) {
    String errorMsg = ((HttpServletRequest) request).getAttribute("errorMsg").toString();
    if(errorMsg.length() > 0) { 
        out.println("<script type=\"text/javascript\">");
        out.println("alert(\"" + errorMsg + "\")");
        out.println("</script>");
    }
}    

} %>
